package com.training.admin.entity.search;

import java.util.Map;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

public class CourseSearch implements QueryBuilder {

	/**
	 * 课程编号
	 */
	private String code;

	/**
	 * 课程名称
	 */
	private String name;

	/**
	 * 课时
	 */
	private Integer hour;

	private QueryFilter filter;

	private QueryOrder order;

	/**
	 * The default constructor
	 */
	public CourseSearch() {

		order = new QueryOrder();

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
	 */
	public QueryFilter getPreparedFilter(boolean refresh) {
		
		if(filter == null || refresh) {
			
			filter = new QueryFilter().addEquals("code", code)
									  .addEquals("name", name)
									  .addEquals("hour", hour);
			
		}
		
		return filter;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
	 */
	public String buildSentenceTemplate() {
		
		String sentence = "FROM Course Where disabled = false "+ getPreparedFilter(false).clauseSentence() + order.sentence();
		
		return sentence;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
	 */
	public Map<String, Object> buildParameters() {

		return getPreparedFilter(false).parameters();
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getHour() {
		return hour;
	}

	public void setHour(Integer hour) {
		this.hour = hour;
	}

	public QueryFilter getFilter() {

		return getPreparedFilter(false);
	}

	public QueryOrder getOrder() {

		return order;
	}
}
